﻿
using Sdg.Domain;
using Sdg.Domain.BizObj;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SDataGen.Views
{
    /// <summary>
    /// Логика взаимодействия для ConnectionView.xaml
    /// </summary>
    public abstract partial  class BaseView : UserControl, IView
    {
        IBizObj _bizObj = null;
        Label lb = new Label();
        protected BaseView()
        {
            // this.Padding = new Thickness(0,25,0,0);
            StackPanel sp = new StackPanel();
            this.Content = sp;
            sp.Orientation = Orientation.Vertical;

            lb.Content = "Title";
            sp.Children.Add(lb);
            SelfRegister();
        }

        public object Title
        {
            set
            {
                lb.Content = value;
            }
            get
            {
                return lb.Content;
            }
        }

        public virtual void SelfRegister()
        {
            //App.Direcrtor.AddView(this);
        }

        public virtual void Bind(IBizObj bizObj)
        {
            _bizObj = bizObj;
            this.DataContext = bizObj;
        }

        protected override void OnMouseEnter(MouseEventArgs e)
        {
            base.OnMouseEnter(e);
            // Background = Brushes.Honeydew;
        }

        protected override void OnMouseLeave(MouseEventArgs e)
        {
            base.OnMouseLeave(e);
            //Background = null;
        }

        public IBizObj BizObject
        {
            get { return _bizObj; }
        }


        public void UnRegister()
        {
            App.Direcrtor.RemoveView(this);
        }


        public event EventHandler<ViewEventArgs> AfterInit;
        public event EventHandler<ViewEventArgs> Done;

        protected virtual void OnAfterInit(object sender, ViewEventArgs args)
        {
            if (AfterInit != null)
                AfterInit(sender, args);
        }

        protected virtual void OnDone(object sender, ViewEventArgs args)
        {
            if (Done != null)
                Done(sender, args);
        }



        public abstract void Notify(ViewEventArgs args);
    }
}
